<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }
    .viewNavMain {
        display: none;
        min-width: 1602px;
        overflow: hidden;
    }
    .viewNavBoxList {
        box-sizing: border-box;
        width: 210px;
        height: 270px;
        float: left;
        border: 1px solid #EDEDED;
        border-radius: 10px;
        margin-right: 20px;
        margin-bottom: 20px;
        position: relative;
        cursor: pointer;
        font-family: Microsoft YaHei-Regular, Microsoft YaHei;
    }
    .viewNavBoxList:nth-child(7n) {
        margin-right: 0;
    }
    .viewNavBoxList .viewNavBoxSpaceNum {
        width: 72px;
        height: 32px;
        box-sizing: border-box;
        position: absolute;
        left: 0;
        top: 8px;
        background-image: url('assets/images/spaceNum.png');
        line-height: 32px;
        text-align: center;
    }
    .viewNavBoxList .viewNavBoxListImg {
        margin: 20px 35px 0;
        width: 140px;
        height: 140px;
    }
    .viewNavBoxListImg img {
        width: 100%;
        height: 100%;
    }
    .viewNavBoxList .viewNavBoxListTitle {
        box-sizing: border-box;
        padding: 0 10px;
        margin-top: 14px;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
        line-height: 19px;
        text-align: center;
        height: 40px;
        width: 100%;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
    }
    .viewNavBoxList .viewNavBoxListBottom {
        position: absolute;
        width: 100%;
        left: 0;
        bottom: 0;
        height: 40px;
        background: #FAFBFF;
        border-radius: 0 0 10px 10px;
        padding: 0 14px;
        box-sizing: border-box;
    }
    .viewNavBoxListBottom > span {
        box-sizing: border-box;
        text-align: center;
        line-height: 40px;
        font-size: 12px;
        font-weight: 400;
        color: #333333;
        float: left;
    }

    .viewNavBoxListBottom > span:last-child {
        float: right;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt" style="width: calc(82% - 160px)">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">规格码：</label>
                                    <div class="layui-input-inline">
                                        <input name="oldSpecCode" class="layui-input" type="text" placeholder="请输入规格码"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
<!--                                <div class="layui-inline">-->
<!--                                    <div class="viewNav" id="viewNav">-->
<!--                                        <div class="viewNavList active"><img src="assets/images/navlist1.png">列表</div>-->
<!--                                        <span></span>-->
<!--                                        <div class="viewNavGraphics"><img src="assets/images/navgraphics.png">图文</div>-->
<!--                                    </div>-->
<!--                                </div>-->
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit>查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
<!--                                    <button id="cellInventoryProductExport" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>-->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="sluggishMaterialsTable" lay-filter="sluggishMaterialsTable"></table>
            <div class="viewNavMain" id="viewNavMain">
                <div class="viewNavBox" style="" id="viewNavBox">
                    <!-- <div class="viewNavBoxList">
                         <div class="viewNavBoxSpaceNum">A12</div>
                         <div class="viewNavBoxListImg"><img src="assets/images/login_lt.png" alt=""></div>
                         <div class="viewNavBoxListTitle">展示规格码展示规</div>
                         <div class="viewNavBoxListBottom">
                             <span>物料编号</span>
                             <span>库存数</span>
                         </div>
                     </div>
                     <div class="viewNavBoxList"></div>
                     <div class="viewNavBoxList"></div>-->
                </div>
                <div id="viewNavPage" style="text-align: right;"></div>
            </div>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="sluggishMaterialsTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">设置时间区间</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="storageInventoryInoutForm">
    <form lay-filter="storageInventoryInoutForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label">物料</label>
            <div class="layui-input-block">
                <select name="skuId" id="skuId4simple" lay-filter="skuId" lay-verify="required" lay-search required disabled></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">时间</label>
            <div class="layui-inline">
                <div class="layui-input-inline" style="width: 160px;">
                    <input type="text" class="layui-input" name="startDay" id="startDay" placeholder="开始天数" lay-verify="required" required>
                </div>
                <div class="layui-form-mid">至</div>
                <div class="layui-input-inline" style="width: 160px;">
                    <input type="text" class="layui-input" name="endDay" id="endDay" placeholder="结束天数" lay-verify="required" required>
                </div>
                <div class="layui-form-mid">天</div>
            </div>
        </div>


        <div align="center" >
            <div class="layui-form-item text-right saveCancelBtn" >
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button class="layui-btn" lay-filter="storageInventoryInoutFormSubmit" lay-submit>提交</button>
            </div>
        </div>
    </form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laypage','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var layDate = layui.laydate;
        var nowTime=new Date();
        // 渲染表格
        var insTb = table.render({
            elem: '#sluggishMaterialsTable',
            url: config.base + 'enterprisecab/cabinet/admin/cellMaterialTimezoneSetting/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                , {field: 'skuName', title: '物料名称'}
                , {field: 'skuCode', sort: true, title: '物料编号'}
                , {field: 'skuSpecOld', title: '规格码'}
                , {field: 'productBrandName', title: '品牌'}
                , {field: 'quantity', sort: true, title: '库存'}
                , {align: 'center', toolbar: '#sluggishMaterialsTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {
            }
        });

        // 工具条点击事件
        table.on('tool(sluggishMaterialsTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            }
        });

        //监听排序
        table.on('sort(sluggishMaterialsTable)', function (obj) {
            table.reload('sluggishMaterialsTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });


        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for(let key in field){
                field[key] = ''
            }
            insTb.reload({where: field,page: {curr: 1}},'data');
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: ['980px','300px'],
                offset: '65px',
                title: '设置时间区间',
                content: $('#storageInventoryInoutForm').html(),
                success: function () {
                    admin.req('enterprisecab/cabinet/admin/cellMaterialTimezoneSetting/getMaterialTimezoneBySkuCode?skuCode='+data.skuCode, {}, function (res) {
                        if (res.code == 200) {
                            $("#startDay").val(res.data.startDay)
                            $("#endDay").val(res.data.endDay)
                        }
                    }, 'GEt');
                    //, 'GET', true);
                    admin.req('enterprise/product/admin/productDetail/list', {limit:999}, function (res) {
                        if (res.code == 200) {
                            var html='<option value="">请选择物料</option>'
                            for(var k=0;k<res.data.length;k++){
                                html+='<option value="'+res.data[k].id+'"data-skucode="'+res.data[k].skuCode+'">'+'物料编号:'+res.data[k].skuCode+'|物料名称:'+res.data[k].skuName+'|规格:'+res.data[k].oldSpecCode+'</option>'
                            }
                            $("#skuId4simple").html(html);
                            if(data){
                                $("#skuId4simple").val(data.skuId);
                                form.render('select');
                                // getCabSpace(data.cabId,data.skuCode);
                            }
                            form.render('select');
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GEt');

                    form.val('storageInventoryInoutForm', data);
                    // 表单提交事件
                    form.on('submit(storageInventoryInoutFormSubmit)', function (d) {
                        console.log(d.field)
                        layer.load(2);
                        admin.req('enterprisecab/cabinet/admin/cellMaterialTimezoneSetting/add', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('sluggishMaterialsTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        },'POST', true, 'application/json; charset=utf-8');
                         return false;
                    });
                }
            });
        }


        //导出按物料库存数据
        $('#cellInventoryProductExport').click(function () {

            location.href = config.base + 'enterprisecab/cabinet/admin/cellInventoryProduct/export';
        });

    });
</script>